﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Reflection;
using System.Web.UI.WebControls;

using Developmentalmadness.Web.UI.AjaxAbstractions;

namespace Developmentalmadness.Web.UI.ExtJsControlLibrary
{
    public abstract class ExtJsBoxComponent : ExtJsComponent
    {
        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.BoxComponent";

            String[] properties = new String[]{
                "autoHeight", "autoWidth", "height", "pageX", 
                "pageY", "width", "x", "y"
            };

            Type component = typeof(ExtJsBoxComponent);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'ExtJsBoxComponent.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                    continue;

                if (!(value is String))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }

            return list;
        }

        public Boolean? autoHeight { get; set; }

        public Boolean? autoWidth { get; set; }

        public Unit? height { get; set; }

        public Int32? pageX { get; set; }

        public Int32? pageY { get; set; }

        public Unit? width { get; set; }

        public Int32? x { get; set; }

        public Int32? y { get; set; }
    }
}
